// 导入 axios
import axios from 'axios'
// 导入 react-vant 消息模块
import { Toast } from 'react-vant'
// 创建 axios 实例
const service = axios.create({
  baseURL: 'http://localhost:3001',
  timeout: 6000,
})
// 请求拦截
service.interceptors.request.use(
  config => {
    /* if (config.method == 'post') {
      config.data = {
        ...config.data,
        _t: Date.parse(new Date()) / 1000
      }
    } else if (config.method == 'get') {
      config.params = {
        ...config.params,
        _t: new Date().getTime().toString()
      }
    } */
    config.data = JSON.stringify(config.data)
    config.headers = {
      'Content-Type': 'application/json; charset=utf-8', //配置请求头
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    Toast.info(error)
  }
)

export default service
